package com.smart.common.config.satoken;

import cn.dev33.satoken.interceptor.SaInterceptor;
import com.smart.common.aop.AccessLimitInterceptor;
import com.smart.common.cache.CacheService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * sa牌配置
 *
 * @author 夏绪秋
 * @date 2022-11-07
 */
@Component
@Log4j2 @RequiredArgsConstructor
public class SaTokenInterceptor implements WebMvcConfigurer {
    private final CacheService cacheService;
    /**
     * 注册Sa-Token的注解拦截器，打开注解式鉴权功能
     *
     * @param registry 注册表
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.error("header拦截器....");
        registry.addInterceptor(new WapInterceptor()).order(0);
        //限流拦截器
        log.error("限流拦截器装载成功....");
        registry.addInterceptor(new AccessLimitInterceptor(cacheService)).order(1);
        // 注册注解拦截器，并排除不需要注解鉴权的接口地址 (与登录拦截器无关)
        registry.addInterceptor(new SaInterceptor()).addPathPatterns("/**").order(2);
        log.error("权限拦截器装载成功....");
    }



}
